package com.rui.test2;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket {
    //属性 方法  面向对象编程

    private int number = 30;

    Lock lock = new ReentrantLock();

    //买票的方式
    public void sale() {

        lock.lock();

        try {
            if(number > 0){
                number--;
                System.out.println(Thread.currentThread().getName() + "卖出了" + (50 - number) + "张票，剩余："+ number+ "张票");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
}
